<!-- 试听课点评 -->

<template>
  <div class="evaluation_month_container">
    <template>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        

    
        <!-- 校区分析 -->
        <el-tab-pane label="校区分析" name="schoolAnalysis">
          <div class="search_box">
            <div @click="exportSchool" class="btn btn_add">
              <i class="el-icon-plus"></i>
              <span class="btn_txt">导出</span>
            </div>

            <div class="btn btn_search fr" @click="searchSchoolAnalysis(searchFormSchoolAnalysis)">
              <span class="btn_txt">查询</span>
            </div>

            <div class="fr">
              <el-form :model="searchFormSchoolAnalysis" :inline="true" class="searchFormSchoolAnalysis">
                <el-form-item size="small">
                  <el-select  clearable style="width:200px;"  v-model="searchFormSchoolAnalysis.schoolId" placeholder="选择校区">
                    <el-option v-for="(item,key) in schoolList" :key="key" :label="item.schoolName" :value="item.schoolId">
                    </el-option>
                  </el-select>
                </el-form-item> 

                <el-form-item size="small">
                  <el-date-picker
                    style="width:230px;"
                    v-model="searchFormSchoolAnalysis.financialMonth"
                    type="daterange"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker>
                </el-form-item>

                
              </el-form>
            </div>
            
            <div class="clear"></div>
          </div>

          <div class="table_box month_box">
            <adminTable :tableHead="tableHeadSchoolAnalysis" :tableData="tableDataSchoolAnalysis" ></adminTable>
            <el-pagination
              class="pagination"
              @size-change="handleSizeChangeSchool"
              @current-change="handleCurrentChangeSchool"
              :current-page="pageSchoolAnalysis.curPage"
              :page-sizes="[10, 20, 50]"
              :page-size="pageSchoolAnalysis.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pageSchoolAnalysis.totalRows">
            </el-pagination>
          </div>
        </el-tab-pane>
        <!-- 校区分析 end-->

        <!-- 逐题分析 -->
        <el-tab-pane label="逐题分析" name="qsAnalysis">
          <question-analysis :questionType="'listenToTheClass'" :isActiveEcharts="isActiveEcharts"></question-analysis>
        </el-tab-pane>
        <!-- 逐题分析 end-->

      </el-tabs>
    </template>

  </div>
</template>


<style>

  .evaluation_month_container .el-radio__input.is-checked+.el-radio__label {
    color: #FC8434 !important;
  }
  .evaluation_month_container .el-radio__input.is-checked .el-radio__inner {
    border-color: #FC8434 !important;
    background: #FC8434 !important;
  }

  .evaluation_month_container .table_box {
    box-shadow: none;
  }
  .evaluation_month_container .el-tabs__nav {
    background: #fff;
  }
  .evaluation_month_container .el-tabs__header {
    margin-bottom: 0;
  }
  .evaluation_month_container .el-tabs__content {
    box-shadow: 2px 2px 8px 4px rgba(213,212,212,0.5);
    padding-top: 15px;
    box-sizing: border-box;
    background: #fff;
  }
  .evaluation_month_container .el-tabs--card>.el-tabs__header .el-tabs__nav {
    /* border-bottom: 1px solid #E4E7ED; */
    border-radius: 3px 3px 0 0;
  }
  .evaluation_month_container .el-tabs__item {
    height: 35px;
    line-height: 35px;
    font-size: 12px !important;
    border-bottom: 1px solid #E4E7ED !important;
  }
  .evaluation_month_container .el-tabs__content{
    border-left: 1px solid #E4E7ED;
  }

  .evaluation_month_container .el-tabs__item.is-active {
    color: #FC8434;
    border-bottom: 1px solid #fff !important;
  }
  
</style>
<style scoped>



.select_box{
  padding: 0 0 15px 15px;
}


.month_table_item{
  margin-bottom: 25px;
  position: relative;
}
.month_table .month_table_item:last-child {
  margin-bottom: 0;
}
.addMonth{
  cursor: pointer;
  color: #77A4FF;
  text-align: right;
  padding: 10px 0;
  float: right;
}
.deleteMonth{
  position: absolute;
  right: 10px;
  top: 0;
}
.addProduct {
  cursor: pointer;
  line-height: 25px;
  color: #77A4FF;
}
.tab_box{
  padding-left: 15px;
  margin-bottom: 10px;
}

.table_box .table_title {
  background: #F5F7FA;
  text-align: right;
  height: 30px;
  line-height: 30px;
  color: #77A4FF;
  font-size: 12px;
  padding-right: 20px;
}

.tab_box .btn_tab.isActive {
  background: #77A4FF;
  color: #fff;
}
.tab_box .btn_tab {
  width:70px;
  height:25px;
  line-height: 25px;
  margin-right: 15px;
  color: #77A4FF;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  border: 1px solid #77A4FF;
  border-radius:15px;
}
.tab_box .btn_tab:hover {
  background: #77A4FF;
  color: #fff;
}

.btn_search {
  padding: 0 20px;
  text-align: center;
  height: 32px;
  font-size: 12px;
  background: #FBA56C;
  line-height: 32px;
}
.search_box {
  padding: 0 15px;
  box-sizing: border-box;
}
</style>

<script>
import adminTable from '@/components/assembly/adminTable';
import eidtTable from '@/components/assembly/eidtTable'
import questionAnalysis from '@/components/page/system_management/evaluateManagement/questionAnalysis'
import {
  createNamespacedHelpers,
  mapState,
} from "vuex";
let {
  // mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("evaluationAudition");



export default {
  name: 'evaluationAudition',
  data() {
    return {
      activeName: 'schoolAnalysis',
      jwtAuth: {},
      isActiveEcharts: false,
      schoolList: [],
      subjectList: [],

    /* ===== 校区分析 ====== */
      searchFormSchoolAnalysis: {
        schoolId: '',
        financialMonth: [],
        rptTimeStart: '',
        rptTimeEnd: '',
      },
      tableHeadSchoolAnalysis: {
        data: [
          {
            name: "校区",
            key: "schoolName",
            align: "center",
          },
          {
            name: "校区编号",
            key: "schoolCode",
            align: "center",
          },
          {
            name: "教师姓名",
            key: "employeesName",
            align: "center"
          },
          {
            name: "工号",
            key: "workNo",
            align: "center"
          },
          {
            name: "评价人数",
            key: "evaluationNumber",
            align: "center",
          },
          {
            name: "平均得分",
            key: "averageScore",
            align: "center"
          },
        ]
      },
      tableDataSchoolAnalysis: [],
      pageSchoolAnalysis: {
        curPage: 1,
        pageSize: 10,
        totalRows: 0,
      },
    /* ===== 校区分析 END ====== */

    
    }
  },
  created() {
    this.jwtAuth = JSON.parse(sessionStorage.getItem('jwtAuth'));
    
    

    if(sessionStorage.getItem('adutionTabName')) {
      this.activeName = sessionStorage.getItem('adutionTabName');
    }else{
      this.activeName = 'schoolAnalysis'
    }

    if(this.activeName == 'qsAnalysis') {
      this.isActiveEcharts = true;
    }else{
      this.queryAllSchool();
      this.initSchoolAnalysisData();
      this.isActiveEcharts = false;
    }

    console.log(this.isActiveEcharts)



  },
  mounted() {

  },
  watch: {
    
  },
  methods: {
    ...mapMutations([
      "updateInfo",
    ]),
    ...mapActions([
      "formGet",
      "post",
      "export"
    ]),

    exportSchool() {
      let data = {
        rptTimeStart: this.searchFormSchoolAnalysis.financialMonth[0] || '',
        rptTimeEnd: this.searchFormSchoolAnalysis.financialMonth[1] || '',
        // schoolId: this.searchFormSchoolAnalysis.schoolId,
      };

      let schoolIdArr = [];
      data.schoolId = this.searchFormSchoolAnalysis.schoolId
      console.log(data.schoolId)
      if(!data.schoolId || data.schoolId.length == 0) {
        this.schoolList.forEach(item => {
          schoolIdArr.push(item.schoolId);
        })
        data.schoolId = schoolIdArr;
      }else{
        data.schoolId = this.searchFormSchoolAnalysis.schoolId
      }

      // Object.assign(data, this.searchFormSchoolAnalysis)
      this.export({
        API: 'exportBmExamplesPageListForAudition',
        data: data
      }).then(res => {

      }).catch(err => {
        this.$message.error(err);
      })
    },

    queryAllSchool(btnId) {
      let accountId
      this.jwtAuth.schoolId == '' ? accountId = '' : accountId = this.jwtAuth.accountId

      // let schoolIds = null
      // let arr = this.jwtAuth.schoolId.split(',')
      // console.log(arr);
      // for(let i=0; i<arr.length; i++) {
      //   if(arr[i] == '') {
      //     schoolIds = [];
      //     break;
      //   }else{
      //     schoolIds = this.jwtAuth.schoolId.split(',')
      //   }
      // }
      this.post({
        API: 'queryAllSchool',
        data: {
          accountId: accountId,
          menuId: btnId || this.$route.name,
          schoolIds: this.jwtAuth.schoolId.split(','),
        }
      }).then(res => {
        // if(btnId) {
        //   this.powerSchoolList = res
        //   this.formDataMonth.schoolId = this.powerSchoolList[0].schoolId
        //   if(this.activeName == 'monthly') {
        //     this.changeMonthSchool(this.formDataMonth.schoolId)
        //   }
          
        // }else{
        //   this.schoolList = res
        // }
        this.schoolList = res;
        this.schoolList = this.schoolList.filter(val => {
          return val.schoolId !== '';
        });
        // this.powerSchoolList = res;
      }).catch(err => {
        this.$message.error(err);
      })
    },

    

    handleClick(tab, event) {
      
      sessionStorage.setItem('adutionTabName', tab.name);
      switch (tab.name) {
        
        case 'schoolAnalysis':
          this.initSchoolAnalysisData();
          this.isActiveEcharts = false;
          break;
        case 'qsAnalysis':
          // this.initMonthData();
          this.isActiveEcharts = true;
          break;
      
        default:
          break;
      }
    },



  /* ========================= 校区分析START =========================== */
    searchSchoolAnalysis(searchFormSchoolAnalysis) {
      this.pageSchoolAnalysis.curPage = 1;
      this.initSchoolAnalysisData(searchFormSchoolAnalysis)
    },

    initSchoolAnalysisData(searchForm) {
      // console.log(searchValue)
      let searchValue = searchForm || this.searchFormSchoolAnalysis || '';
      let data = {}
      Object.assign(data, searchValue);
      data.curPage = this.pageSchoolAnalysis.curPage;
      data.pageSize = this.pageSchoolAnalysis.pageSize;
      data.accountId = this.jwtAuth.accountId;
      data.menuId = this.$route.name;
      // data.schoolId = []

      let schoolIdArr = [];
      if(!data.schoolId || data.schoolId.length == 0) {
        // this.schoolList.forEach(item => {
        //   schoolIdArr.push(item.schoolId);
        // })
        // schoolIdArr.push('');
        data.schoolId = [];
      }else{
        schoolIdArr.push(this.searchFormSchoolAnalysis.schoolId)
      }

      // if(this.searchFormSchoolAnalysis.schoolId) {
      //   data.schoolId.push(this.searchFormSchoolAnalysis.schoolId)
      // }

      data.schoolId = schoolIdArr

      if(this.searchFormSchoolAnalysis.financialMonth && this.searchFormSchoolAnalysis.financialMonth.length > 0) {
        data.rptTimeStart = this.searchFormSchoolAnalysis.financialMonth[0];
        data.rptTimeEnd = this.searchFormSchoolAnalysis.financialMonth[1];
      }
      

      this.post({
        API: 'queryBmExamplesPageListForAudition',
        data: data
      }).then(res => {
        if(data.schoolId && data.schoolId.length > 0) {
          this.tableDataSchoolAnalysis = res.data.filter(val => {
            return val.schoolId == this.searchFormSchoolAnalysis.schoolId
          });


        }
        else{
          this.tableDataSchoolAnalysis = res.data
        }

        /** 
          if(res.buttons) {
            res.buttons.menuList[0].children.forEach(item => {
              if(item.label == '新建班级') {
                this.powerList.add.show = 1
                this.powerList.add.menuId = item.menuId
              }
              
              console.log(this.powerList)
            })
          }
        */


        this.tableDataSchoolAnalysis.sort((a, b) => {
          return a.schoolCode - b.schoolCode
        })

        this.pageSchoolAnalysis = res.page;
      }).catch(err => {
        this.$message.error(err);
      })
    },
    
    
    handleSizeChangeSchool(val) {
      this.pageSchoolAnalysis.pageSize = val;
      this.initSchoolAnalysisData();
    },
    handleCurrentChangeSchool(val) {
      this.pageSchoolAnalysis.curPage = val;
      this.initSchoolAnalysisData();
    },
  /* ========================= 校区分析END =========================== */
  

  

  },
  computed: {
    ...mapState([
      "selectProductId",
    ]),

    
    
  },
  components: {
    adminTable,
    eidtTable,
    questionAnalysis,
  },
}

</script>